package com.bing.jh.controller;

import cn.hutool.core.text.CharSequenceUtil;
import com.bing.bingPro.common.BaseResult;
import com.bing.bingPro.controller.dto.TFiveOrderTypeDto;
import com.bing.bingPro.controller.vo.TLstfOrderVo;
import com.bing.bingPro.util.ExcelData;
import com.bing.bingPro.util.ProvinceUtil;
import com.bing.bingPro.util.WebExcelUtil;
import com.bing.jh.entity.ProbeDetailEntity;
import com.bing.jh.entity.ProbeRankEntity;
import com.bing.jh.entity.dto.MdSoftProbeRelStatsDTO;
import com.bing.jh.entity.dto.ProbeMissDto;
import com.bing.jh.entity.dto.ProbeMissPageDto;
import com.bing.jh.entity.vo.MdSoftProbeRelStatsVO;
import com.bing.jh.service.MdSoftProbeRelStatsService;
import com.bing.jh.service.NEProbeMissService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/mdSoftProbeRelStats")
public class MdSoftProbeRelStatsController {

    @Resource
    private MdSoftProbeRelStatsService mdSoftProbeRelStatsService;

    @Autowired
    private NEProbeMissService neProbeMissService;

    @PostMapping("list")
    public BaseResult<List<MdSoftProbeRelStatsVO>> list(@RequestBody MdSoftProbeRelStatsDTO infoDTO) {
        return new BaseResult<>(mdSoftProbeRelStatsService.list(infoDTO));
    }


    @PostMapping("/export")
    public void exportLowFullness(HttpServletResponse response, @RequestBody MdSoftProbeRelStatsDTO infoDTO) throws Exception {
        List<MdSoftProbeRelStatsVO> list = mdSoftProbeRelStatsService.list(infoDTO);
        //整理查询的数据
        List<ExcelData> excelDataList = new ArrayList<>();
        ExcelData excelData = new ExcelData(MdSoftProbeRelStatsVO.class,
                list);
        excelDataList.add(excelData);
        String province = (CharSequenceUtil.isNotEmpty(ProvinceUtil.getKeyProvince(infoDTO.getProvince()))) ? "全国" : ProvinceUtil.getKeyProvince(infoDTO.getProvince());
        //写出到浏览器
        WebExcelUtil.download(response, "三类探针关联结果-" + infoDTO.getDt()+"-"+province, excelDataList);
    }

    @PostMapping("dateList")
    public BaseResult<List<String>> dateList() {
        return new BaseResult<>(mdSoftProbeRelStatsService.dateList());
    }

    @PostMapping("provinceList")
    public BaseResult<List<String>> provinceList() {
        return new BaseResult<>(mdSoftProbeRelStatsService.provinceList());
    }


    @PostMapping("/queryDetailData")
    public BaseResult<PageInfo<ProbeDetailEntity>> queryDetailData(@RequestBody ProbeMissPageDto probeMissDto) {
        PageInfo<ProbeDetailEntity> dataList = neProbeMissService.queryDetailData(probeMissDto);
        return new BaseResult<>(dataList);
    }

    @PostMapping("/queryIndexRankingChart")
    public BaseResult<List<ProbeRankEntity>> queryIndexRankingChart(@RequestBody ProbeMissDto probeMissDto) {
        return new BaseResult<>(neProbeMissService.queryIndexRankingChart(probeMissDto));
    }
}
